package de.atos.kata.fizzbuzz.impl;

import java.util.HashMap;

public class FizzBuzz implements FizzBuzzIf {

	private HashMap<Integer, String> mapping = new HashMap<Integer, String>();
	
	public FizzBuzz(){
		for (int i = 1; i <= 100; i++) {
			if (isDivisableByThree(i) && isDivisableByFive(i)){
				mapping.put(i, "FizzBuzz");
			} else if (isDivisableByThree(i) || String.valueOf(i).contains("3")){
				mapping.put(i, "Fizz");
			} else if (isDivisableByFive(i) || String.valueOf(i).contains("5")){
				mapping.put(i, "Buzz");
			} else {
				mapping.put(i, String.valueOf(i));
			}
		}
	}
	
	private boolean isDivisableByThree(int i){
		return (i % 3 == 0);
	}
	
	private boolean isDivisableByFive(int i){
		return (i % 5 == 0);
	}
	
	/* (non-Javadoc)
	 * @see de.atos.kata.fizzbuzz.impl.FizzBuzzIf#getAt(java.lang.Integer)
	 */
	@Override
	public String getAt(Integer x){
		if (mapping.containsKey(x)){
			return mapping.get(x);
		} else {
			return null;
		}
	}
	
	/* (non-Javadoc)
	 * @see de.atos.kata.fizzbuzz.impl.FizzBuzzIf#printMapping()
	 */
	@Override
	public void printMapping(){
		for (int i = 1; i <= 100; i++) {
			System.out.println(i + ": " + mapping.get(i));
		}
	}
}
